package org.ellwood.core.utils;

import org.springframework.util.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * @ProjectName: ellwood-boot-pro
 * @PackageName: org.ellwood.common.core.utils
 * @ClassName: FileUploadUtils
 * @Description: // 上传文件名处理工具类
 * @Author: Ellwood
 * @CreateDate: 2024/6/12 - 上午11:26
 * @Version: V1.0.0
 */
public class FileUploadUtils {

    /**
     * 生成文件名
     * @param originalFilename 原始文件名
     * @return {@link String}
     */
    public static String generateFileName(String originalFilename){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String localTime = sdf.format(new Date());
        String pathStr="/"+localTime+"/";
        String extension= StringUtils.getFilenameExtension(originalFilename);
        String fileName= UUID.randomUUID().toString();
        return pathStr+fileName+"."+extension;
    }

}
